class SceneStart extends Scene {
  constructor(game) {
    super(game)
    this.setup()
  }

  setup() {
    this.addBG()
    this.addLabel()
    this.addPlayer()

    this.game.registerAction('Enter', state => {
      if (state === 'up' && this.game._scene === this) {
        const scene_main = new SceneMian(this.game)
        this.game.over = false
        this.game.replaceScene(scene_main)
      }
    })

  }

  addBG() {
    this.bg = new Spirit('img/title.jpg')
    this.add(this.bg)
  }

  addLabel() {
    this.label = new Label('提示: 按 Enter 开始游戏！ 按 空格 发射子弹')
    this.label.color = '#032455'
    this.label.x = 30
    this.label.y = 500

    this.add(this.label)
  }

  addPlayer() {
    this.player = new Player()
    this.player.scale(0.5)
    this.player.x = (game.canvas.width - this.player.w) / 2
    this.player.y = 400

    this.game.registerAction('a', (state) => {
      console.log(state);
      this.player.moveLeft()
    })

    this.game.registerAction('d', () => {
      this.player.moveRight()
    })

    this.game.registerAction('w', () => {
      this.player.moveUp()
    })

    this.game.registerAction('s', () => {
      this.player.moveDown()
    })

    this.game.registerAction(' ', () => {
      this.player.fire()
    })

    this.add(this.player)
  }

}